package queue

import C "gitee.com/ljfirst/algo-go-sdk/common/constant"

/**
 * @author ljfirst
 * @version V1.0
 * @date 2023/6/27 01:00
 * @author-Email ljfirst@mail.ustc.edu.cn
 * @blogURL https://blog.csdn.net/ljfirst
 * @description
 * */
type ArrayQueue struct {
	queue []int
	cap   int
}

func (m *ArrayQueue) Offer(value int) {
	if len(m.queue) == m.cap {
		m.Resize()
	}
	m.queue = append(m.queue, value)
}

func (m *ArrayQueue) Poll() int {
	if len(m.queue) == 0 {
		return C.ErrorNum
	}
	value := m.queue[0]
	m.queue = m.queue[1:len(m.queue)]
	return value
}

func (m *ArrayQueue) Peak() int {
	if len(m.queue) == 0 {
		return C.ErrorNum
	}
	return m.queue[0]
}

func (m *ArrayQueue) Size() int {
	return len(m.queue)
}

func (m *ArrayQueue) Resize() {
	m.cap *= 2
}

func (m *ArrayQueue) StructName() string {
	return "ArrayQueue"
}
